package com.srm.psu.glf;

import java.io.IOException;
import java.util.ArrayList;

import javax.microedition.khronos.opengles.GL10;

import org.anddev.andengine.audio.music.Music;
import org.anddev.andengine.audio.music.MusicFactory;
import org.anddev.andengine.engine.Engine;
import org.anddev.andengine.engine.camera.Camera;
import org.anddev.andengine.engine.handler.IUpdateHandler;
import org.anddev.andengine.engine.handler.physics.PhysicsHandler;
import org.anddev.andengine.engine.handler.timer.ITimerCallback;
import org.anddev.andengine.engine.handler.timer.TimerHandler;
import org.anddev.andengine.engine.options.EngineOptions;
import org.anddev.andengine.engine.options.EngineOptions.ScreenOrientation;
import org.anddev.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
import org.anddev.andengine.entity.primitive.Rectangle;
import org.anddev.andengine.entity.scene.Scene;
import org.anddev.andengine.entity.scene.Scene.IOnAreaTouchListener;
import org.anddev.andengine.entity.scene.Scene.IOnSceneTouchListener;
import org.anddev.andengine.entity.scene.menu.MenuScene.IOnMenuItemClickListener;
import org.anddev.andengine.entity.scene.Scene.ITouchArea;
import org.anddev.andengine.entity.scene.CameraScene;
import org.anddev.andengine.entity.scene.background.AutoParallaxBackground;
import org.anddev.andengine.entity.scene.background.ColorBackground;
import org.anddev.andengine.entity.scene.background.ParallaxBackground.ParallaxEntity;
import org.anddev.andengine.entity.scene.menu.MenuScene;
import org.anddev.andengine.entity.scene.menu.item.IMenuItem;
import org.anddev.andengine.entity.scene.menu.item.TextMenuItem;
import org.anddev.andengine.entity.scene.menu.item.decorator.ColorMenuItemDecorator;
import org.anddev.andengine.entity.shape.Shape;
import org.anddev.andengine.entity.sprite.AnimatedSprite;
import org.anddev.andengine.entity.sprite.Sprite;
import org.anddev.andengine.entity.text.ChangeableText;
import org.anddev.andengine.entity.text.Text;
import org.anddev.andengine.entity.util.FPSLogger;
import org.anddev.andengine.extension.physics.box2d.PhysicsConnector;
import org.anddev.andengine.extension.physics.box2d.PhysicsFactory;
import org.anddev.andengine.extension.physics.box2d.PhysicsWorld;
import org.anddev.andengine.extension.physics.box2d.util.Vector2Pool;
import org.anddev.andengine.input.touch.TouchEvent;
import org.anddev.andengine.opengl.font.Font;
import org.anddev.andengine.opengl.font.FontFactory;
import org.anddev.andengine.opengl.texture.Texture;
import org.anddev.andengine.opengl.texture.TextureOptions;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.anddev.andengine.opengl.texture.region.TextureRegion;
import org.anddev.andengine.opengl.texture.region.TiledTextureRegion;
import org.anddev.andengine.ui.activity.BaseGameActivity;
import org.anddev.andengine.util.Debug;
import org.anddev.andengine.util.HorizontalAlign;

import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.hardware.SensorManager;
import android.widget.Toast;

import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.BodyDef.BodyType;
import com.badlogic.gdx.physics.box2d.FixtureDef;

import android.view.KeyEvent;

public class AutoParallaxBackgroundExample extends BaseGameActivity implements IOnSceneTouchListener, IOnAreaTouchListener, IOnMenuItemClickListener {
	// ===========================================================
	// Constants
	// ===========================================================

	private static final int CAMERA_WIDTH = 720;
	private static final int CAMERA_HEIGHT = 480;
	
	protected static final int MENU_QUIT = 1;      	// Same values as in MainMenuActivity
	protected static final int MENU_RESUME = 99;
	protected static final int MENU_PLAY = 100;
	protected static final int MENU_OPTIONS = 102;
	
	private static int SCORE = 0;					// Stores score of user
	
	// ===========================================================
	// Fields
	// ===========================================================

	private Camera mCamera;
	private int playerX;
	private int playerY;
	private ArrayList<AnimatedSprite> enemies;

	private BitmapTextureAtlas mBitmapTextureAtlas;
	private TiledTextureRegion mPlayerTextureRegion;

	private BitmapTextureAtlas mAutoParallaxBackgroundTexture;
	private BitmapTextureAtlas mPauseTexture;
	private BitmapTextureAtlas mSoundTexture;
	private BitmapTextureAtlas mPauseResumeTexture;
    

	private PhysicsHandler physicsHandler3;
	
	private Font mFont;
	private Texture mFontTexture;
	
	private boolean GamePaused = false;
	
    private TextureRegion mPauseResume;
	private TextureRegion mParallaxLayerBack;
	private TextureRegion mParallaxLayerMid;
	private TextureRegion mParallaxLayerFront;
	private TiledTextureRegion meggs;
	private TiledTextureRegion menemy;
	private TiledTextureRegion menemy2;
	private TextureRegion mpause;
	private TextureRegion mSoundRegion;
	private float mid_speed=10.0f;
	private long freq=120;
	private static float DEMO_VELOCITY = 10.0f;
	
	final Scene scene=new Scene();
	
	// Sound
	static protected Music mMusic;
	private SharedPreferences audioOptions;
	private SharedPreferences.Editor audioEditor;
	
	private PhysicsWorld mPhysicsWorld;
	// ===========================================================
	// Constructors
	// ===========================================================
	private float mGravityX;
	private float mGravityY;
	private AnimatedSprite player;
	private Sprite pauseButton;
	private Sprite pauseResumeButton;
	private Sprite soundButton;
	
	private boolean isMusicPlaying;

	// ===========================================================
	// Getter & Setter
	// ===========================================================

	// ===========================================================
	// Methods for/from SuperClass/Interfaces
	// ===========================================================

	@Override
	public Engine onLoadEngine() {
		this.mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
		return new Engine(new EngineOptions(true, ScreenOrientation.LANDSCAPE, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), this.mCamera).setNeedsMusic(true));
		//final EngineOptions engineOptions = new EngineOptions(true, ScreenOrientation.LANDSCAPE, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), mCamera);
		//engineOptions.getTouchOptions().setRunOnUpdateThread(true);
		//return new Engine(engineOptions);
	}

	@Override
	public void onLoadResources() {
		BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
		
		this.mPauseResumeTexture = new BitmapTextureAtlas(1024, 1024, TextureOptions.BILINEAR);
		this.mFontTexture = new BitmapTextureAtlas(256, 256, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
		FontFactory.setAssetBasePath("font/");
		this.mFont = FontFactory.createFromAsset(this.mFontTexture, this, "HeeHawRegular.ttf", 32, true, Color.BLACK);
		this.mEngine.getTextureManager().loadTexture(this.mFontTexture);
		this.mEngine.getFontManager().loadFont(this.mFont);
		
		this.mBitmapTextureAtlas = new BitmapTextureAtlas(1024, 1024, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
		this.mPauseTexture = new BitmapTextureAtlas(1024, 1024, TextureOptions.BILINEAR);
		this.mSoundTexture = new BitmapTextureAtlas(1024, 1024, TextureOptions.BILINEAR);
		this.mPlayerTextureRegion = BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(this.mBitmapTextureAtlas, this, "player.png", 0, 0, 3, 4);
		this.meggs=BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(this.mBitmapTextureAtlas, this, "coins.png", 200, 120, 4, 4);
		this.menemy=BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(this.mBitmapTextureAtlas, this, "enemy.png", 200, 200, 3, 4);
		this.menemy2=BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(this.mBitmapTextureAtlas, this, "BlueApe.png", 200, 600, 1, 6);
		this.mpause=BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mPauseTexture, this, "pause.png", 0, 0);
		this.mSoundRegion=BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mPauseTexture, this, "sound.png", 110, 0);
		
		this.mPauseResume=BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mPauseResumeTexture, this, "back.png", 0, 0);
		
		this.mEngine.getTextureManager().loadTexture(this.mPauseResumeTexture);

		this.mAutoParallaxBackgroundTexture = new BitmapTextureAtlas(1024, 1024, TextureOptions.DEFAULT);
		this.mParallaxLayerFront = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mAutoParallaxBackgroundTexture, this, "parallax_background_layer_front.png", 0, 0);
		this.mParallaxLayerBack = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mAutoParallaxBackgroundTexture, this, "parallax_background_layer_back.png", 0, 188);
		this.mParallaxLayerMid = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mAutoParallaxBackgroundTexture, this, "parallax_background_layer_mid.png", 0, 669);
		this.mEngine.getTextureManager().loadTextures(this.mBitmapTextureAtlas, this.mAutoParallaxBackgroundTexture, this.mPauseTexture);
		
		// Sound
		MusicFactory.setAssetBasePath("mfx/");
		try {
			AutoParallaxBackgroundExample.mMusic = MusicFactory.createMusicFromAsset(
					this.mEngine.getMusicManager(), getApplicationContext(),
					"mbg1.ogg");
			AutoParallaxBackgroundExample.mMusic.setLooping(true);
		} catch (final IOException e) {
			Debug.e(e);
		}
		isMusicPlaying=true;
	}

	@Override
	public Scene onLoadScene() {
		
		SCORE = 0;
		
		this.mEngine.registerUpdateHandler(new FPSLogger());
		this.enemies=new ArrayList<AnimatedSprite>();
		
		this.mPhysicsWorld = new PhysicsWorld(new Vector2(0, SensorManager.GRAVITY_EARTH), false);
		//this.mPhysicsWorld = new FixedStepPhysicsWorld(30, 1, new Vector2(0, SensorManager.GRAVITY_EARTH), false, 8, 4);
		
		// Sound
		if (OptionsActivity.isMusicOn && !mMusic.isPlaying())
			mMusic.play();
		

		//final Scene scene = new Scene();
		final AutoParallaxBackground autoParallaxBackground = new AutoParallaxBackground(0, 0, 0, 5);
		autoParallaxBackground.attachParallaxEntity(new ParallaxEntity(0.0f, new Sprite(0, CAMERA_HEIGHT - this.mParallaxLayerBack.getHeight(), this.mParallaxLayerBack)));
		autoParallaxBackground.attachParallaxEntity(new ParallaxEntity(-5.0f, new Sprite(0, 80, this.mParallaxLayerMid)));
		autoParallaxBackground.attachParallaxEntity(new ParallaxEntity(-10.0f, new Sprite(0, CAMERA_HEIGHT - this.mParallaxLayerFront.getHeight(), this.mParallaxLayerFront)));
		scene.setBackground(autoParallaxBackground);
		this.scene.setOnSceneTouchListener(this);

		/* Calculate the coordinates for the face, so its centered on the camera. */
		playerX = (CAMERA_WIDTH - this.mPlayerTextureRegion.getTileWidth()) / 5;
		playerY = CAMERA_HEIGHT - this.mPlayerTextureRegion.getTileHeight()-30;
		//final int eggX=this.meggs.getTileWidth();

		/* Create two sprits and add it to the scene. */
		final Body body;
		final FixtureDef objectFixtureDef = PhysicsFactory.createFixtureDef(1, 0.5f, 0.5f);
		player = new AnimatedSprite(playerX, playerY, this.mPlayerTextureRegion);
		player.setScaleCenterY(this.mPlayerTextureRegion.getTileHeight());
		player.setScale(4);
		body = PhysicsFactory.createBoxBody(this.mPhysicsWorld, player, BodyType.DynamicBody, objectFixtureDef);
		this.mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(player, body, true, true));
		player.animate(new long[]{120, 120, 120}, 3, 5, true);
		player.setUserData(body);
		this.scene.registerTouchArea(player);
	
		// create pause button and set touch action
		pauseButton = new Sprite(CAMERA_WIDTH-120, 20, this.mpause){
			@Override
			public boolean onAreaTouched(final TouchEvent pSceneTouchEvent, final float pTouchAreaLocalX,
					final float pTouchAreaLocalY){
				switch(pSceneTouchEvent.getAction()){
					case TouchEvent.ACTION_DOWN:
						break;
					case TouchEvent.ACTION_UP:
						// will later bring up the pause menu
						//Toast.makeText(AutoParallaxBackgroundExample.this, "Pause button pressed!", Toast.LENGTH_SHORT).show();
						displayPauseMenu();
						break;
					default:
						break;
				}
				return true;
			}
		};
		this.scene.registerTouchArea(pauseButton);
		
		// Begin High Score Code
		final ChangeableText scoreText;			// Object to display score text
		scoreText = new ChangeableText(10, 10, this.mFont, String.format("%06d", SCORE), 6);
		scene.attachChild(scoreText);
		scene.registerUpdateHandler(new TimerHandler(1 / 20.0f, true, new ITimerCallback()
		{
		    @Override
		    public void onTimePassed(final TimerHandler pTimerHandler)
		    {
		    	// Increases the score by 1 and updates the text
		    	scoreText.setText(String.format("%06d", ++SCORE));
		    }
		}));
		// End High Score Code
		
		// create sound button and attach touch action
		soundButton=new Sprite(CAMERA_WIDTH-70, 100, this.mSoundRegion)
		{
			@Override
			public boolean onAreaTouched(final TouchEvent pSceneTouchEvent, final float pTouchAreaLocalX,
					final float pTouchAreaLocalY){
				switch(pSceneTouchEvent.getAction()){
					case TouchEvent.ACTION_DOWN:
						break;
					case TouchEvent.ACTION_UP:
						// check whether the music is on and start/stop it accordingly
						if(OptionsActivity.isMusicOn){
							OptionsActivity.isMusicOn=false;
							mMusic.pause();
						}
						else{
							OptionsActivity.isMusicOn=true;
							if (!mMusic.isPlaying())
								mMusic.resume();
						}
						break;
					default:
						break;
				}
				return true;
			}
			
			
		};
		this.scene.registerTouchArea(soundButton);
		this.scene.setTouchAreaBindingEnabled(true);

//		final AnimatedSprite eggs = new AnimatedSprite(CAMERA_WIDTH-30, CAMERA_HEIGHT/2, this.meggs);
//		final AnimatedSprite eggs1 = new AnimatedSprite(CAMERA_WIDTH-50, CAMERA_HEIGHT/2-20, this.meggs);
//		final AnimatedSprite eggs2 = new AnimatedSprite(CAMERA_WIDTH-50, CAMERA_HEIGHT/2+20, this.meggs);
//		final AnimatedSprite menemy = new AnimatedSprite(CAMERA_WIDTH-50, playerY, this.menemy);
		
//		menemy.setScaleCenterY(this.mPlayerTextureRegion.getTileHeight());
//		menemy.setScale(6);
//		menemy.animate(new long[]{90, 90, 90}, 9, 11, true);//(new long[]{50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50}, 0, 15, true);
		
		
		
		
//		eggs.setScaleCenterY(this.meggs.getTileHeight());
//		eggs.setScale(1);
//		eggs.animate(new long[]{50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50}, 0, 15, true);
		
//		eggs1.setScaleCenterY(this.meggs.getTileHeight());
//		eggs1.setScale(1);
//		eggs1.animate(new long[]{50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50}, 0, 15, true);
		
//		eggs2.setScaleCenterY(this.meggs.getTileHeight());
//		eggs2.setScale(1);
//		eggs2.animate(new long[]{50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50}, 0, 15, true);
		
		pauseButton.setScaleCenterY(this.mpause.getHeight());
		pauseButton.setScale(1);
		
		soundButton.setScaleCenterY(this.mSoundRegion.getHeight());
		soundButton.setScale(1);
		
		scene.attachChild(player);
//		scene.attachChild(eggs);
		
//		scene.attachChild(eggs1);
//		scene.attachChild(eggs2);
//		scene.attachChild(menemy);
		scene.attachChild(pauseButton);
		scene.attachChild(soundButton);
		
		
//		physicsHandler3 = new PhysicsHandler(menemy);
//        menemy.registerUpdateHandler(physicsHandler3);
//		physicsHandler3.setVelocityX(-30);
		
//		final PhysicsHandler physicsHandler = new PhysicsHandler(eggs);
//        eggs.registerUpdateHandler(physicsHandler);
//		physicsHandler.setVelocityX(-10);
		
//        final PhysicsHandler physicsHandler1 = new PhysicsHandler(eggs1);
//        eggs1.registerUpdateHandler(physicsHandler1);
//        physicsHandler1.setVelocityX(-10);
        
//        final PhysicsHandler physicsHandler2 = new PhysicsHandler(eggs2);
//        eggs2.registerUpdateHandler(physicsHandler2);
//        physicsHandler2.setVelocityX(-10);
        
        final Shape ground = new Rectangle(0, CAMERA_HEIGHT - 2, CAMERA_WIDTH, 2);
		final Shape roof = new Rectangle(0, 0, CAMERA_WIDTH, 2);
		final Shape left = new Rectangle(0, 0, 2, CAMERA_HEIGHT);
		final Shape right = new Rectangle(CAMERA_WIDTH - 2, 0, 2, CAMERA_HEIGHT);

		final FixtureDef wallFixtureDef = PhysicsFactory.createFixtureDef(0, 0.5f, 0.5f);
		PhysicsFactory.createBoxBody(this.mPhysicsWorld, ground, BodyType.StaticBody, wallFixtureDef);
		PhysicsFactory.createBoxBody(this.mPhysicsWorld, roof, BodyType.StaticBody, wallFixtureDef);
		PhysicsFactory.createBoxBody(this.mPhysicsWorld, left, BodyType.StaticBody, wallFixtureDef);
		PhysicsFactory.createBoxBody(this.mPhysicsWorld, right, BodyType.StaticBody, wallFixtureDef);

		this.scene.attachChild(ground);
		this.scene.attachChild(roof);
		this.scene.attachChild(left);
		this.scene.attachChild(right);

		this.scene.registerUpdateHandler(this.mPhysicsWorld);

		this.scene.setOnAreaTouchListener(this);
		
        scene.registerUpdateHandler(new TimerHandler(20.0f / 10.0f, true, new ITimerCallback() {
            
        	@Override
            public void onTimePassed(final TimerHandler pTimerHandler) {

              autoParallaxBackground.setParallaxChangePerSecond(mid_speed);
              mid_speed=mid_speed+0.5f;
              player.animate(new long[]{ freq, freq, freq}, 3, 5, true);
              
//              physicsHandler.setAccelerationX(-mid_speed);
              
//              physicsHandler1.setAccelerationX(-mid_speed);
              
//             physicsHandler2.setAccelerationX(-mid_speed);
//              physicsHandler3.setAccelerationX(-mid_speed);  
        	}
		}));
        
        scene.registerUpdateHandler(new TimerHandler((int)(Math.random()*5+4), true, new ITimerCallback(){
			@Override
			public void onTimePassed(TimerHandler pTimerHandler) {
				AnimatedSprite enemy=createEnemy();
				enemies.add(enemy);
				scene.attachChild(enemy);
			}
        	
        }));
        
        final DbHelper dbhelper = new DbHelper(this);
        
        // collision detection
        scene.registerUpdateHandler(new IUpdateHandler() {
        	@Override
        	public void reset() { }

        	@Override
        	public void onUpdate(final float pSecondsElapsed)
        	{
        		for(AnimatedSprite enemy : enemies)
        		{
        			if (player.collidesWith(enemy))
        			{
            			// Return to main menu screen and **CARL** save score
        				
        				dbhelper.addScore(SCORE);
        				SCORE = 0;
        				mMusic.stop();
        				AutoParallaxBackgroundExample.this.finish();
            		}
        		}
      			for(final AnimatedSprite enemy : enemies){
        			// remove enemies that are past the player--they won't collide anymore
        			if(enemy.getX()<playerX)
        				AutoParallaxBackgroundExample.this.runOnUpdateThread(new Runnable(){
							public void run() {
								enemies.remove(enemy);								
							}
        					
        				});
        			}
        	}}
        		);
		return scene;
	}
	

	@Override
	public void onLoadComplete() {

	}

	@Override
	public boolean onSceneTouchEvent(Scene pScene, TouchEvent pSceneTouchEvent) {
			if(pSceneTouchEvent.isActionDown()) {
				final AnimatedSprite face = (AnimatedSprite) player;
				this.jumpFace(face);
				return true;
			}
		// TODO Auto-generated method stub
		return false;
	}
	
	@Override
	public boolean onAreaTouched(TouchEvent pSceneTouchEvent,ITouchArea pTouchArea, float pTouchAreaLocalX,float pTouchAreaLocalY) {
		if(pSceneTouchEvent.isActionDown()) {
			final AnimatedSprite face = (AnimatedSprite) player;
			this.jumpFace(face);
			return true;
		}
		// TODO Auto-generated method stub
		return false;
	}
	
	@Override
	public boolean onMenuItemClicked(final MenuScene pMenuScene, final IMenuItem pMenuItem, final float pMenuItemLocalX, final float pMenuItemLocalY) {
		
		Intent myIntent;
		switch(pMenuItem.getID()){
		case MENU_RESUME:				// Pause Menu Handler
			if(scene.hasChildScene())
			{
				scene.clearChildScene();
			}
			return true;
		case MENU_PLAY:
			this.finish();
			myIntent = new Intent(this, AutoParallaxBackgroundExample.class);
			this.startActivity(myIntent);
			return true;
		case MENU_QUIT:
			AutoParallaxBackgroundExample.this.mMusic.stop();
			this.finish();
			myIntent = new Intent(this, MainMenuActivity.class);
			this.startActivity(myIntent);
			return true;
			
		default:
			scene.clearChildScene();
			return false;
		}
		
	}

	private void jumpFace(final AnimatedSprite face) {
		final Body faceBody = (Body)face.getUserData();
		final Vector2 velocity = Vector2Pool.obtain(0, 40);
		faceBody.setLinearVelocity(velocity);
		Vector2Pool.recycle(velocity);
	}
	
	private AnimatedSprite createEnemy()
	{
		AnimatedSprite enemy;
		enemy = new AnimatedSprite(CAMERA_WIDTH-50, playerY, this.menemy);
		
		enemy.setScaleCenterY(this.mPlayerTextureRegion.getTileHeight());
		enemy.setScale(4);
		enemy.animate(new long[]{90, 90, 90}, 9, 11, true);
		PhysicsHandler physicsHandler = new PhysicsHandler(enemy);
        enemy.registerUpdateHandler(physicsHandler);
		physicsHandler.setVelocityX((int)(-(Math.random()*50+200)));
		return enemy;
	}
	// ===========================================================
	// Methods
	// ===========================================================
	protected MenuScene createPauseMenuScene() {
		// Create the pause menu scene
		MenuScene mPauseMenuScene = new MenuScene(this.mCamera);

		final IMenuItem resumeMenuItem = new ColorMenuItemDecorator( new TextMenuItem(MENU_RESUME, mFont, "Resume"), 0.0f, 0.0f, 0.0f, 0f, 0f, 0f);
		resumeMenuItem.setBlendFunction(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
		resumeMenuItem.setPosition((CAMERA_WIDTH/2)-(resumeMenuItem.getWidth()/2), CAMERA_HEIGHT/5);
		mPauseMenuScene.addMenuItem(resumeMenuItem);

		final IMenuItem restartMenuItem = new ColorMenuItemDecorator( new TextMenuItem(MENU_PLAY, mFont, "Restart"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
		restartMenuItem.setBlendFunction(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
		restartMenuItem.setPosition((CAMERA_WIDTH/2)-(restartMenuItem.getWidth()/2), (3*CAMERA_HEIGHT)/10);
	    mPauseMenuScene.addMenuItem(restartMenuItem);

		final IMenuItem quitMenuItem = new ColorMenuItemDecorator( new TextMenuItem(MENU_QUIT, mFont, "Quit"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
	    quitMenuItem.setBlendFunction(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
	    quitMenuItem.setPosition((CAMERA_WIDTH/2)-(quitMenuItem.getWidth()/2), (2*CAMERA_HEIGHT)/5);
		mPauseMenuScene.addMenuItem(quitMenuItem);
		
		mPauseMenuScene.setBackgroundEnabled(false);

		mPauseMenuScene.setOnMenuItemClickListener(this);
		
		
		return mPauseMenuScene;
	}
	
	public void displayPauseMenu()
	{
		if(this.mEngine.isRunning()) 
		{
			// Overlay the game with the pause menu
			this.GamePaused = true;
			this.scene.setChildScene(this.createPauseMenuScene(), false, true, true);
	    } 
		else
		{
			//Toast.makeText(this, "PAUSE selected", Toast.LENGTH_SHORT).show();
		}
		
	}
	// ===========================================================
	// Inner and Anonymous Classes
	// ===========================================================
	
	
}